#include <bits/stdc++.h>
using namespace std;
int g(int x)
{
    int result = 0;
    while(x>0)
    {
        result += x%10;
        x /= 10;
    }
    return result;
}
int f(int x)
{
    int result = 0;
    while(x)
    {
        ++result;
        x = x&(x-1);
    }
    return result;
}
int main() {
    int n;
    cin>>n;
    int cnt = 0;
//    cout<<f(20)<<endl;
//    cout<<f(20)<<" "<<g(20)<<" ";
    for(int i=1;i<n+1;i++)
    {
        if(f(i) == g(i))
            cnt++;
    }
    cout<<cnt;
    return 0;
}